package cn.iocoder.yudao.module.erp.taskListener;

import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveServiceImpl;
import cn.iocoder.yudao.module.erp.enums.ErpSupplierStatus;
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * OA 请假单的结果的监听器实现类
 *
 * @author 芋道源码
 */
@Component
public class BpmSupplierStatusListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private ErpSupplierService erpSupplierService;

    @Value("${task.supplier_apply.key:supplier_apply_audit}")
    private String supperApplyTask;

    @Override
    protected String getProcessDefinitionKey() {
        return supperApplyTask;
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        Integer status = event.getStatus();
        if(BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(status)){
            erpSupplierService.updateStatus(Long.parseLong(event.getBusinessKey()), ErpSupplierStatus.PASS.getStatus());
        }else if(BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(status)
        || BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(status)){
            erpSupplierService.updateStatus(Long.parseLong(event.getBusinessKey()), ErpSupplierStatus.REJECT.getStatus());
        }

    }

}
